import { GanZhi } from "../../common/ganzhi";

export type MonthDayItem = {
	year : undefined | number,
	/** 月份. 1 ~ 12或13. 闰月及后面的月数都比实际月数大1 */
	month : undefined | number,
	/** 日数. 1 ~ 31[29,30] */
	day : undefined | number,
	mode : undefined | '公历' | '农历',
	/** 月份索引 0 ~ 11或12. 闰月及后面的月数都比实际月数大1 */
	monthIndex : number | undefined,
	/** 闰月数 */
	leapMonth : number | undefined,
}
export class HourItem {
	mode : undefined | '24小时' | '十二时辰';
	hour : number | undefined;
	minute : number | undefined;
	dayGanzhi : GanZhi | undefined;
	hasHour : boolean;
	getText(getDiZhiText : (hour24 : number) => string) {
		if (!this.hasHour) return "不知道";
		if (this.mode == '24小时') {
			return this.hour.toString() + "点" + (this.minute ? this.minute.toString() + "分" : "") + "(" + getDiZhiText(this.hour) + "时)";
		} else {
			let hour = Math.floor(this.hour / 2) * 2;
			return getDiZhiText(this.hour) + "时(" + (hour - 1).toString() + " - " + (hour + 1).toString() + "点)";
		}
	};
	static createItem(mode : '24小时' | '十二时辰', dayGanzhi : GanZhi | undefined, hasHour : boolean) {
		let obj = new HourItem();
		obj.mode = mode;
		obj.dayGanzhi = dayGanzhi;
		obj.hasHour = hasHour;
		obj.hour = 0;
		return obj;
	}
}